using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using TTDotNet.Engine.ThreeDEngine;

using TTDotNet.Util;

namespace TTDotNet.Engine.GUI.Windows
{
    public class WindowTitle : Control
    {
        private Microsoft.DirectX.Direct3D.Font font;
        private Coordinate coord;

        private GameTexture bg;
        private Sprite s;

        private Rectangle size;
        private Rectangle actualSize;
        private Vector3 center;
        private Vector3 actualPosition;

        private String titleText;       

        private float width, height;

        public WindowTitle(Coordinate coord)
        {
            InitializeFont();
            
            this.coord = coord;
            
            InitializeSprite();

            center = new Vector3();
            size = new Rectangle(0, 0, bg.Texture.GetLevelDescription(0).Width, bg.Texture.GetLevelDescription(0).Height);
            actualSize = new Rectangle(0, 0, bg.Texture.GetLevelDescription(0).Width, bg.Texture.GetLevelDescription(0).Height);
            
            actualPosition = new Vector3();
        }

        private void InitializeFont()
        {
            System.Drawing.Font systemFont = new System.Drawing.Font("Tahoma", 12f);
            font = new Microsoft.DirectX.Direct3D.Font(Game.device, systemFont);
        }

        private void InitializeSprite()
        {
            string path = "artwork/colours/red.jpg";
            bg = Game.textureCacher.LoadTexture(path);
            s = new Sprite(Game.device);

            width = bg.Width;
            height = bg.Height;

        }

        public override void SetSize(float newWidth, float newHeight)
        {
            float widthScale = newWidth / width;
            float heightScale = newHeight / height;

            width = newWidth;
            height = newHeight;

            actualSize.Width = (int)width;
            actualSize.Height = (int)width;

            Matrix stretch = Matrix.Scaling(widthScale, heightScale, 1f);

            s.Transform = stretch;
        }

        public override void Render(PointF location)
        {
            Game.guiSprite.Transform = spriteTransform;
            Game.guiSprite.Draw(textureUp.Texture, Rectangle.Empty, Vector3.Empty, Vector3.Add(_renderPosition, new Vector3(location.X / WidthScale, location.Y / HeightScale, 0)), Color.White);

            if (!_text.Equals(string.Empty))
            {
                Game.guiSprite.Transform = Matrix.Identity;
                _font.DrawText(Game.guiSprite, _text, new Rectangle((int)(_textRect.X + location.X), (int)(_textRect.Y + location.Y), (int)_textRect.Width, (int)_textRect.Height), textFormat, _fontColor);
                Game.guiSprite.Transform = spriteTransform;
            }
        }

        public String Name
        {
            get { return titleText; }
            set { titleText = value; }
        }


    }
}
